<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" name="viewport" />
<title>停车一道通</title>
<script  type="text/javascript" src="../../resource/js/zepto.min.js"></script>
 <link rel="stylesheet" href="../../resource/frozen/css/frozen.css">
 <script src="../../resource/frozen/js/frozen.js"></script>
<script src="../../resource/js/result.js"></script>
<script src="../../resource/js/common.js"></script>
<script src="../../resource/js/template.js"></script>
<script src="../../resource/js/pageTemplate.js"></script>
<script src="../../resource/js/phoneTip.js"></script>
 <script src="../../resource/js/md5.js"></script>
</head>
<body>

   <header class="ui-header ui-header-positive ui-border-b">
            <i class="ui-icon-return" onclick="history.back()"></i><h1>手机验证</h1>
        </header>
<section class="ui-container">
   <div class="ui-form ui-border-t">
                    <div class="ui-form-item ui-form-item-r ui-border-b">
                        <input type="text" placeholder="请输入手机号" name="cellphone" id="Check_code" onblur="phoneReg()">
                        <!-- 若按钮不可点击则添加 disabled 类 -->
                        <button type="button" class="ui-border-l" id="J_BtnMobileCode"><span id="fff">发送</span></button>
                    </div>
                      <div class="ui-form-item ui-form-item-pure ui-border-b">
                        <input type="text" placeholder="验证码" name="code" id="code">
                    </div>
                    <div class="ui-form-item ui-form-item-pure ui-border-b">
                        <input type="password" placeholder="输入新密码" name="password" id="pwd1">
                    </div>
                    <div class="ui-form-item ui-form-item-pure ui-border-b">
                        <input type="password" placeholder="确认密码" name="rePassword" id="pwd2">
                    </div>
                     <div class="ui-btn-wrap">
                <button class="ui-btn-lg ui-btn-primary" id="Input_login">
                    确定
                </button>
            </div>
            </div>
</section>

<script>

function phoneReg(){
	var val = $("#Check_code").val();
	if(val.trim()==""){
		frozen_warn("请输入手机号");
		return;
	}
	var re =/^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/; 
	if (!re.test(val)||val.length!=11) {
		frozen_warn("手机号输入不正确");
	    return false;
	}else{
		return true;
	}
}


$("#J_BtnMobileCode").click(function(){
	if(!phoneReg()){
		return false;
	}
	if(vcode_status==0){
		$.ajax({ 
		    type:"POST",
		    url:linkPre+'/ydtu/tmember/getCode.htm',
			data : {
	  			"codeType" : 1,
	  			"phone" : $("#Check_code").val()
			},
			dataType : 'json',
			success : function(data) {
				checkResult(data.result);
				if(data.result == 'FAIL'){
 					frozen_warn("该号码非注册会员");
					return false;
				}else{
					settime();
				}
			}
		}); 
	}
});
var vcode_status=0;
var countdown = 60;

function settime() {
	countdown--;
	if(countdown <= 0){
		vcode_status=0;
		$("#fff").text("获取验证码"); 
		countdown = 60;
	}else {
		setTimeout(settime, 1000);
		vcode_status=1;
		$("#fff").text(countdown+"秒"); 
	}
}

function sub(){
	$.ajax({
		type: "post",
		url:linkPre+ "/ydtu/tmember/resetPassword.htm",
		data: {"cellphone":$("#Check_code").val(),"password":hex_md5($("#pwd1").val())},
		dataType: "json",
		success: function(data){
			checkResult(data.result);
			if(data.result == SUCCESS){
				frozen_info("修改成功");
				setTimeout(function(){
					location.href="login.html";
				}, 2000 )
				
			}		
		}
	})
}
$("#Input_login").click(function(){
	var pwd1=$("#pwd1").val();
	var pwd2=$("#pwd2").val();
	if(pwd1.length<6){
		frozen_warn("密码长度大于6位");
		return false;
	}
	if(pwd1!=pwd2){
		frozen_warn("两次密码输入不一致");
		return false;
	}
	
	$.ajax({
		type:"POST",
		url:linkPre+'/ydtu/tmember/validate_code.htm',
		data : {
  			"code" : $("#code").val(),
  			"phone" : $("#Check_code").val()
		},
		dataType : 'json',
		async:false,
		success : function(data) {
			checkResult(data.result);
			if (data.result == FAIL) {
				frozen_warn("验证码错误");
				return;
			}else{
				sub();
			}
		}					
	});

})

</script>
</body>
</html>